home *** CD-ROM | disk | FTP | other *** search
- /*
- Copyright © 1994 Mikhal Fridberg.
- Telnet - based talk server.
- this client/server application uses MacTCP to implement a simple talk server. the server
- opens up several listeners on kGreetingPort (1235). when a client connects over telnet, the data entered
- in the greeting dialog is sent to the remote connection, server opens 2 windows - one to talk, one to to listen
- and beeps many times. No restrictions for connctions are added. It was a quick hack,
- written for specific application, and it has few bugs that I never fixed, since I
- didn't need it anymore.
- Connection management is done through the use of Operating System queues to simplify tracking
- and usage.
- */
-
-
- #include <CommResources.h>
- #include <Terminals.h>
- #include <Connections.h>
- #include <Traps.h>
- #include <ConnectionTools.h>
- #include <CTBUtilities.h>
- #include <TCPPB.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <errno.h>
- #include <time.h>
- #include <stddef.h>
- #include <string.h>
- #include <assert.h>
-
- #include "const.h"
- #include "globals.h"
- #include "utils.h"
- #include "queues.h"
- #include "network.h"
- #include "events.h"
- #include "interface.h"
- #include "main.h"
-
- /* main entry point */
-
- TermHandle gTerm, gTermRec;
- Ptr gRecvBuffer;
- Ptr gSendBuffer;
- long gTimeCount = 0;
-
- void main(void)
- {
- int err;
-
- printf(" ");
- InitMac();
- InitQueues();
- InitInterface();
-
- if (InitNetwork()!=noErr)
- ExitToShell();
- if (err=InitCRM() != noErr) {
- CloseNetwork();
- TMDispose(gTerm);
- TMDispose(gTermRec);
- ExitToShell();
- }
- if (err = InitCTBUtilities() != noErr){
- CloseNetwork();
- ExitToShell();
- }
- if (err = InitTM() !=noErr){
- CloseNetwork();
- ExitToShell();
- }
- gRecvBuffer = NewPtr(kRcvBuffSize);
- gSendBuffer = NewPtr(kRcvBuffSize);
- MainLoop();
-
- CloseNetwork();
- TMDispose(gTerm);
- TMDispose(gTermRec);
- ExitToShell();
- }
-
- pascal long TermSendProc(Ptr thePtr,long theSize, long refcon, short flags)
- { static long savecount;
-
- if (gNoSendDataPending) {
- if (theSize > 0) {
- if (memchr(thePtr, '\r', theSize) || memchr(thePtr, '\n', theSize)){
- BlockMove(thePtr, &gSendBuffer[savecount], theSize);
- gSendBuffer[theSize+savecount] = 0x00;
- gNoSendDataPending = FALSE;
- savecount = 0;
- return theSize;
- } else {
- BlockMove(thePtr, &gSendBuffer[savecount], theSize);
- savecount += theSize;
- return 0L;
- }
-
- }
- return 0L;
- }
- }
-
-
- pascal OSErr ToolGetConnEnvirons(long refcon, ConnEnvironRec *theEnvirons)
- {
- }
- /* initialize macintosh managers and some globals */
-
- void InitMac(void)
- {
- SysEnvRec envRec;
-
- InitGraf(&qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(nil);
- InitCursor();
- FlushEvents(everyEvent,0);
-
- if (SysEnvirons(1,&envRec)!=noErr)
- gRunningSeven = false;
- else
- gRunningSeven = (envRec.systemVersion >= 0x700);
-
- if (gRunningSeven)
- GetCurrentProcess(&gOurPSN);
- }
-
-
- /* main event loop. note that we use a *very* large sleeptime if we're running under System 7
- */
-
- #define GetSleepTime 100
-
- void MainLoop(void)
- {
- EventRecord ev;
- MyQElemPtr iopb;
- long len;
- int err;
- CMFlags flags = 0L;
-
- while (!gDone) {
- if (WaitNextEvent(everyEvent,&ev,GetSleepTime,nil)) {
- HandleEvent(&ev);
- HandleIdleTime(&ev);
-
-
- }
- else HandleIdleTime(&ev);
- UpdateNumberList();
- }
- }
-
-